package fenyu.personblob.bean.strategy.user;

import fenyu.personblob.bean.databean.User;
import fenyu.personblob.bean.strategy.Strategy;
import fenyu.personblob.error.NotFoundError;
import fenyu.personblob.single.SinglePathDoor;

/**
 * create at 2018/12/22 8:45
 *
 * @author 纷羽 <gzj0078@gmail.com>
 */
public class ChangePowerStrategy implements Strategy {

    @Override
    public Object todo(Object... args) {
        Integer user_id = (Integer) args[0];
        String type = (String) args[1];
        User user_old = SinglePathDoor.getSingleSave().getSaveDoor().getUserSavePath().getById(user_id);
        if (user_old == null)
            throw new NotFoundError();
        User user = (User) SinglePathDoor.getSingleFuns().getAutoFactory().createUser(type);
        user.setUsername(user_old.getUsername());
        user.setNickname(user_old.getNickname());
        user.setPassword(user_old.getPassword());
        user.setStatue(user_old.getStatue());
        user.setToken(user_old.getToken());
        SinglePathDoor.getSingleSave().getSaveDoor().getUserSavePath().save(user);
        return user;
    }
}
